package com.jumi.microservice.service;

import com.jumi.microservice.common.base.dto.BaseResponse;
import com.jumi.microservice.dto.PayNotifyRequest;
import com.jumi.microservice.dto.PaymentRequest;
import com.jumi.microservice.dto.PaymentResponse;
import com.jumi.microservice.dto.RefundRequest;
import com.jumi.microservice.interfaces.BasePayment;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * @author Dirk
 * @Date 2020-07-20 14:19
 */
@DubboService
public class PayServiceImpl implements IPayService {

    /**
     * 执行支付
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse execPay(PaymentRequest request) {
        return BasePayment.paymentMap.get(request.getPayChannel().name()).process(request);
    }

    /**
     * 支付结果回调
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse paymentNotify(PayNotifyRequest request) {
        return BasePayment.paymentMap.get(request.getPayChannel()).completePayment(request);
    }

    /**
     * 退款
     *
     * @param request
     * @return
     */
    @Override
    public PaymentResponse refund(RefundRequest request) {
        return BasePayment.paymentMap.get(request.getPayChannel().name()).refund(request);
    }

}
